﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using EBookStore.Books;

namespace EBookStore.UnitTests
{
    [TestFixture]
    [Category("objects test")]
    public class Test_Catalog
    {

        Catalog c1;
        Catalog c2;

        [SetUp]
        public void init()
        {
            c1 = Catalog.Instance;
            c2 = Catalog.Instance;
        }

        [TearDown]
        public void clear()
        {
            Catalog.Instance.Clear();
            c1 = null;
            c2 = null;
        }


        [Test]
        public void InstanceTest()
        {            
            // both must be the same
            Assert.AreSame(c1, c2);
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void addSameBookTwice()
        {
            Book b1 = new Book("123");
            c1.AddBook(b1);
            c2.AddBook(b1);            
        }


        [Test]        
        public void addBooksInTwoInstances()
        {
            Book b1 = new Book("321");
            Book b2 = new Book("111");
            c1.AddBook(b1);
            c2.AddBook(b2);

            Assert.AreEqual(c2.Count, c1.Count);         
        }


        [Test]
        public void findExistingBooks()
        {
            Book b1 = new Book("333");
            c1.AddBook(b1);
            Assert.AreEqual(b1.ISBN, c1[c1.Count-1].ISBN );            
        }

        

    }
}
